package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /*登录---获取验证码*/
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map){
        String phone = (String) map.get("phone");
        userService.sendMsg(phone);
        return ResponseEntity.ok(null);
    }

    /*登录---验证码校验*/
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map){
        //获取请求的参数
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        //用户登录
        Map retMap =userService.loginVerification(phone,code);
        return ResponseEntity.ok(retMap);
    }
}
